<?php  
 // session_start();
$cate = getSelect('cate',1);

          
          if(!empty($_POST)){



          //开启session
       
// 引用调用的函数
             $savepath = '';
           // print_r($_FILES);die; 

            if (!empty($_FILES['url']['name'][0])) {

              $filelist = array();
              // echo  $filelist;die;

              // 数组重组
        foreach ($_FILES['url']['name'] as $key => $v) {
                 $filelist[$key]['name']=$_FILES['url']['name'][$key];
                 $filelist[$key]['type'] = $_FILES['url']['type'][$key];
                 $filelist[$key]['tmp_name']=$_FILES['url']['tmp_name'][$key];
                 $filelist[$key]['error']=$_FILES['url']['error'][$key];
                 $filelist[$key]['size']=$_FILES['url']['size'][$key];
              }
              
             // print_r($filelist);die;

              foreach ($filelist as $value) {
                
              $savepath = uploads($value);

             
             }
              
             
                  }


                //$_POST的所有数据存储在临时变量中
                 
                  $_POST['send_user']=$_SESSION['admin']['username'];
                  $_POST['url']=empty($savepath[0])?'':$savepath[0];
                 // echo $_POST['url'];die;
               // 清楚$_POST['file']
                unset($_POST['file']);

             $_rows =  add('news',$_POST);

              // insert into `news`(`title`,`type`,`file`,`auther`,`content`)values('','0','Array','','')


            //如果$_rows>0说明成功
            if ($_rows>0) {
                   
                     $id = mysqli_insert_id($link);
                   // echo $id;die;
                     // 获取动态页面数据
                     $constr = file_get_contents("http://127.0.0.1/cms/index.php?c=news&a=des&id=$id");
                     // 写入文件夹生成静态页面
                     file_put_contents("./html/$id.html",$constr);

 
                echo '<script> alert ("新闻数据添加成功");location.href="index.php?c=news&a=list&admin=1";</script>';die;
                   
            }else{

                echo '<script> alert ("新闻数据添加失败");history.go(-1);</script>';
                    die;
            }


            }

  

            $id = empty($_GET['id'])?0:$_GET['id'];

               // $id = $_GET['id'];
              // 顶级分类显示
          
           // $cate = getSelectByOne('cate',1);

           // print_r($cate);die;

          
      

                     // 判断ajax请求
          if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

                
                     
                     if($_GET['ad_se']>0){

                          $data['title'] = $_GET['title'];
                          $data['content'] = $_GET['content'];
                          $data['auther'] = $_GET['auther'];
                          $data['status'] = $_GET['status'];
                          $data['cate_id'] = $_GET['cate_id'];
                           // $data['admin'] = $_POST['send_user'];
                          // $_POST['send_user']=$_SESSION['admin']['username'];
                          // $data['send_user'] = $_POST['send_user'];
                          $data['send_user'] = $_SESSION['admin']['id'];

                          // print_r($_SESSION);die;

                    unset($_GET['c'],$_GET['a'],$_GET['admin'],$_GET['ad_se']);

                       
                       $row = add('news',$data);
                       echo $row;die;

                        }
                       

                   



                       echo json_encode($cate);die;
               }













            //链接news.html的语句
            include (VIEW_PATH.$admin.'/layout.html');

            ?>

